import Vue from 'vue'
import Prompt from '~/components/prompt'
import Confirm from '~/components/confirm'
import Toast from '~/components/toast'

const propertyName = 'notice'

Vue.prototype.$confirm = Confirm
Vue.prototype.$prompt = Prompt

Vue.prototype.$toast = Toast
Vue.mixin({
  beforeCreate () {
    let newProperty = this.$options[propertyName]
    let addedMethods = {}
    for (let key in newProperty) {
      addedMethods[key] = () => { this.$toast(newProperty[key]) }
    }

    if (!newProperty) { return }
    this.$options.methods = Object.assign({
    }, this.$options.methods || {}, addedMethods)
  },

  beforeDestroy () {
    for (let method in this.$options[propertyName]) {
      delete this.$options.methods[method]
    }
  }
})
